home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_147 / sys / bsd / bsd.zoo / spawn.c < prev    next >
C/C++ Source or Header  |  1988-07-25  |  3KB  |  94 lines

  1. /*
  2.  * Spawn. New version, which
  3.  * interracts with the job control stuff
  4.  * in the 4.X BSD C shell.
  5.  * Last edit:  Wed Aug 27 11:16:07 PDT 1986
  6.  * By:           rtech!daveb, to use stop for ksh.
  7.  */
  8. #include    "def.h"
  9.  
  10. #include    <sgtty.h>
  11. #include    <signal.h>
  12. #include    <sys/wait.h>
  13.  
  14. char    *shellp = NULL;            /* Saved "SHELL" name.        */
  15.  
  16. extern    struct    sgttyb    oldtty;        /* There really should be a    */
  17. extern    struct    sgttyb    newtty;        /* nicer way of doing this, so    */
  18. extern    struct    sgttyb    oldtchars;    /* spawn does not need to know    */
  19. extern    struct    sgttyb    newtchars;    /* about the insides of the    */
  20. extern    struct    sgttyb    oldltchars;    /* terminal I/O code.        */
  21. extern    struct    sgttyb    newltchars;
  22.  
  23. extern    char    *getenv();
  24.  
  25. /*
  26.  * This code does a one of 2 different
  27.  * things, depending on what version of the shell
  28.  * you are using. If you are using the C shell, which
  29.  * implies that you are using job control, then MicroEMACS
  30.  * moves the cursor to a nice place and sends itself a
  31.  * stop signal. If you are using the Bourne shell it runs
  32.  * a subshell using fork/exec. Bound to "C-C", and used
  33.  * as a subcommand by "C-Z".
  34.  *
  35.  * Daveb -- changed sense of test so that we only spawn if you
  36.  *        are explicitly using /bin/sh.  This makes it stop
  37.  *        work with the ksh.
  38.  */
  39. /*ARGSUSED*/
  40. spawncli(f, n) {
  41.     register int    pid, wpid, (*oqsig)(), (*oisig)(), omask;
  42.     union wait    status;
  43.  
  44.     if (shellp == NULL) {
  45.         shellp = getenv("SHELL");
  46.         if (shellp == NULL)
  47.             shellp = getenv("shell");
  48.         if (shellp == NULL)
  49.             shellp = "/bin/sh";    /* Safer.        */
  50.     }
  51.     ttcolor(CTEXT);
  52.     ttnowindow();
  53.     if (strcmp(shellp, "/bin/csh") == 0) {
  54.         if (epresf != FALSE) {
  55.             ttmove(nrow-1, 0);
  56.             tteeol();
  57.             epresf = FALSE;
  58.         }                /* Csh types a "\n"    */
  59.         ttmove(nrow-2, 0);        /* before "Stopped".    */
  60.     } else {
  61.         ttmove(nrow-1, 0);
  62.         if (epresf != FALSE) {
  63.             tteeol();
  64.             epresf = FALSE;
  65.         }
  66.     }
  67.     if (ttcooked() == FALSE)
  68.         return (FALSE);
  69.     if (strcmp(shellp, "/bin/sh") != 0) {    /* C shell, ksh        */
  70.         omask = sigsetmask(0);
  71.         (void) kill(0, SIGTSTP);
  72.         (void) sigsetmask(omask);
  73.     } else {                /* Bourne shell.    */
  74.         oqsig = signal(SIGQUIT, SIG_IGN);
  75.         oisig = signal(SIGINT,    SIG_IGN);
  76.         if ((pid=fork()) < 0) {
  77.             (void) signal(SIGQUIT, oqsig);
  78.             (void) signal(SIGINT,  oisig);
  79.             ewprintf("Failed to create process");
  80.             return (FALSE);
  81.         }
  82.         if (pid == 0) {
  83.             execl(shellp, "sh", "-i", NULL);
  84.             _exit(0);        /* Should do better!    */
  85.         }
  86.         while ((wpid=wait(&status))>=0 && wpid!=pid)
  87.             ;
  88.         (void) signal(SIGQUIT, oqsig);
  89.         (void) signal(SIGINT,  oisig);
  90.     }
  91.     sgarbf = TRUE;                /* Force repaint.    */
  92.     return ttraw();
  93. }
  94.